[ Intro ]   [ Lesson1 ]   [ Lesson2 ]   [ Lesson3 ]   [ Lesson4 ]   [ Lesson5 ]   [ Lesson6 ]   [ Lesson7 ]   [ Lesson8 ]

 


Animation

So... then let us look at some live actual aiming scripts. And obviosly to move a piece (like "turret" or "barrel"), that part has to exist. Many game crashes can be related to that.

example

piece base ,body ,turret ,barrel ,flare;

#define SIG_AIM 2

AimPrimary(heading, pitch)
{
signal SIG_AIM;
set-signal-mask SIG_AIM;
turn turret to y-axis heading speed <150>;
turn barrel to x-axis (<0> - pitch) speed <200>;
wait-for-turn turret around y-axis;
wait-for-turn barrel around x-axis;
return(TRUE);
}

This is the script we just examined in Lesson 3. It's quite simple. Note that the amining around the y-axis is set to the angle value "heading". Same thing counts for "pitch", but due to the bug in the engine, you have to invert the value by setting it to "<0> - pitch", or it will aim downwards and look silly. Two lines orders the script to wait until the aiming is completed before opening fire. This is standard procedure, since we normally don't want things to fire square left at a moment's notice.

 

example

piece base ,body ,turret ,barrel ,flare;

static-var reloader;

#define SIG_AIM 2


Create()
{
reloader = 0;
}

AimPrimary(heading, pitch)
{
signal SIG_AIM;
set-signal-mask SIG_AIM;
if (reloader == 30)
{
reloader = 0;
// Reloading animation
}

turn turret to y-axis heading speed <150>;
turn barrel to x-axis (<0> - pitch) speed <200>;
wait-for-turn turret around y-axis;
wait-for-turn barrel around x-axis;
return(TRUE);
}

FirePrimary()
{
reloader = reloader + 1;
}

In case you want to simulate the fire alteration of a real gun, this script will make an animation pause just after the unit have fired 30 shots. You have to define the static var "reloader" and you have to insert a row in FirePrimary( ) - function to get it to work.A lot of preparations, but the it's certainly worth the while.

example

piece base ,body ,turret ,barrel ,flare;

#define SIG_AIM 2

AimPrimary(heading,pitch)
{
signal SIG_AIM1;
set-signal-mask SIG_AIM1;
while( heading > <-45>&& heading < <45> )
{
sleep 200;
}

turn turret to y-axis heading speed <150>;
turn barrel to x-axis (<0> - pitch) speed <200>;
wait-for-turn turret around y-axis;
wait-for-turn barrel around x-axis;
return(TRUE);
}

Now, we are talking about a forward-fire cannon only. It will lock at anything between 45 degrees to left and as much to right, giving the weapon a 90 degree forward span. You will notice quite soon if you set the minus signs and angle values right when you test the unit in the game.

The && signs in the while( ) - argument means "and" in normal language. When both of the asked conditions are set, the script will execute the containment within the function. Otherwise not.

There is a kill signal embedded in the while( ) - function, so that the program don't get stuck there forever. In the same way, it is possible to make weapons that fire backwards or sideways only. It's even technically possible to forbid the weapon to aim every other degree, wherever there is anyone that would want such aiming anyway.

 

example

piece base ,body ,left-turret, right-turret ,left-barrel ,right-barrel, left-flare ,right-flare;

#define SIG_AIM 2

AimPrimary(heading,pitch)
{
signal SIG_AIM1;
set-signal-mask SIG_AIM1;
if(heading < <180>)
{
turn left-turret to y-axis heading speed <150>;
turn left-barrel to x-axis (<0> - pitch) speed <200>;
wait-for-turn left-turret around y-axis;
wait-for-turn left-barrel around x-axis;
}

if(heading >= <180> )
{
turn right-turret to y-axis heading speed <150>;
turn right-barrel to x-axis (<0> - pitch) speed <200>;
wait-for-turn right-turret around y-axis;
wait-for-turn right-barrel around x-axis;
}

return(TRUE);
}

FirePrimary()
{
if(heading < <180>)
{
// recoil animation for left turret
}

if(heading >= <180> )
{
// recoil animation for right turret
}

}

This instant will animate two completely different turrets (that need to have separate names and separate parts in the 3D model) depending on if the enemy is to the left or to the right of the unit. Useful for large ships where you don't want different cannons to turn and fire straight through each other or when you just want certain cannons to aim in certain angles.

more info

recoil examples

Congratulations, if you mastered this part, you can continue reading Lesson 3.


Storm